#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>

using namespace std;

class Solution {
public:
    int findMaxForm(vector<string>& strs, int m, int n) {
        vector<int> cnt0(strs.size());
        for(int i = 0; i < strs.size(); ++i){
            cnt0[i] = count(strs[i].begin(), strs[i].end(), '0');  // 去掉 ranges::
        }

        vector memo(strs.size(), vector(m + 1, vector<int>(n + 1, -1)));
        
        function<int(int, int, int)> dfs;
        dfs = [&](int i, int j, int k)->int{
            if(i < 0) return 0;
            int& res = memo[i][j][k];
            if(res != -1) return res;
            res = dfs(i - 1, j, k);
            int cnt1 = strs[i].size() - cnt0[i];
            if(j >= cnt0[i] && k >= cnt1){
                res = max(res, dfs(i - 1, j - cnt0[i], k - cnt1) + 1);
            }
            return res;
        };
        return dfs(strs.size() - 1, m, n);
    }
};

int main(){
    vector<string> strs = {"10", "0001", "111001", "1", "0"};
    Solution sol;
    cout << sol.findMaxForm(strs, 5, 3);
    return 0;
}